/**
 * TManNetworkManager.java
 * ************************** 
 * @date May 5, 2011
 * @author Michele Tamburini
 * 
 * **************************
 */
package gossipServices.bootstraping.tman;

import gossipServices.gossipMessages.TManMessage;
import gossipServices.network.GeneralServicesMessageDispatcher;
import messages.Message;
import networkRmi.NetworkManager;

/**
 * Description: 
 * This class represents the TMan {@link TManNetworkManager} by simply 
 * extending the {@link GeneralServicesMessageDispatcher} and
 * specifying the classes of the incoming messages and the 
 * passive and active thread of TMan which are:
 * 	- TManMessage : messages exchanged by the service,
 *  - TManPassiveThread : passive thread to which are forwarded the messages
 *  					coming from the active thread of TMan,
 *  - TManActiveThread : active thread to which are forwarded the messages 
 *  					coming from the passive thread of TMan.
 *
 */
public class TManNetworkManager 
	extends GeneralServicesMessageDispatcher {

	protected String tmanInstanceID;
	
	/**
	 * @param networkManager
	 * @param messageClass
	 * @param activeThreadClass
	 * @param passiveThreadClass
	 */
	public TManNetworkManager(NetworkManager networkManager, String tmanInstanceID) {
		super(networkManager, TManMessage.class, 
				TManPassiveThread.class, TManActiveThread.class);
		this.tmanInstanceID = tmanInstanceID;
		
		/* disable the pruning of the waitingIncoming list.
		 * in this service we don't use the age of the NodeDescriptor(s)
		*/
		setUSE_PRUNING_LISTS_METHOD(false);
		
		//Try a blocking TMan procedure
//		nonBlockingReceiveWaitTime = 0;
	}
	
	@Override
	protected boolean messageExtractionAlgorithm(Message m){
		boolean messageType = m.getClass().equals(messageClass);
		boolean tmanId = ((TManMessage)m).getTmanInstanceID().equals(tmanInstanceID);
		
		return (messageType && tmanId);
		
	}
	

}
